<template>
  <div class="main-card">
    <div class="device-header">
      <span class="device-name">设备 {{ device.deviceId }}</span>
      <span class="device-battery">电量: {{ device.batteryLevel }}%
        <i :class="['battery-icon', batteryIconClass]"></i>
      </span>
    </div>
    <div class="device-data">
      <div class="data-item">
        <span>脑电</span>
        <progress-bar :value="device.brainwave" :max="device.brainwaveMax"></progress-bar>
        <span :class="['status', device.connected? 'connected' : 'disconnected']">
          {{ device.connected? '已连接' : '未连接' }}
        </span>
      </div>
      <div class="data-item">
        <span>心率</span>
        <progress-bar :value="device.heartRate" :max="device.heartRateMax"></progress-bar>
      </div>
      <div class="data-item">
        <span>体温</span>
        <progress-bar :value="device.temperature" :max="device.temperatureMax"></progress-bar>
      </div>
      <div class="data-item">
        <span>位置</span>
        <span>{{ device.position1 }}</span>
        <span>{{ device.position2 }}</span>
        <span>{{ device.position3 }}</span>
      </div>
      <div class="data-item">
        <span>血氧</span>
        <progress-bar :value="device.oxygenLevel" :max="device.oxygenLevelMax" :status="device.oxygenStatus"></progress-bar>
      </div>
    </div>
  </div>
</template>

<script>
import ProgressBar from '@/components/ProgressBar.vue';

export default {
  components: { ProgressBar },
  props: {
    device: {
      type: Object,
      required: true
    }
  },
  computed: {
    batteryIconClass() {
      return this.device.batteryLevel > 20? 'battery-icon-full' : 'battery-icon-low';
    }
  }
};
</script>

<style scoped>
.main-card {
  width: 100%;
  height: auto;
  background-color: #ecf0f1;
  border: 1px solid #bdc3c7;
  border-radius: 5px;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
}

.device-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.device-name {
  font-size: 16px;
  font-weight: bold;
}

.device-battery {
  display: flex;
  align-items: center;
}

.battery-icon {
  width: 20px;
  height: 20px;
  margin-left: 5px;
}

.battery-icon-full {
  background-color: green;
}

.battery-icon-low {
  background-color: orange;
}

.device-data {
  width: 100%;
}

.data-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 5px;
}

.status {
  padding: 3px 8px;
  border-radius: 5px;
}

.connected {
  background-color: lightgreen;
  color: green;
}

.disconnected {
  background-color: lightcoral;
  color: red;
}
</style>